#pragma once

#include "limbo/ip/state.hpp"
#include "opts.h"
#include "udp_context.hpp"
#include "udp_packet.hpp"

namespace limbo::udp {

template <typename NextState, int options = {}> struct State {
  using Context = UdpContext<State>;
  using Packet = UdpPacket<State>;
  using LowerState = NextState;
  using LowerPacket = details::lower_packet_t<LowerState>;
  static constexpr int opts = options;

  Result recv(Chunk buff, LowerState *lower_state) {
    return packet.recv(buff, *this, lower_state);
  }

  Packet &get_parsed() { return packet; }

  inline bool select(const LowerPacket *packet) {
    return packet->proto == static_cast<uint8_t>(ip::Proto::udp);
  }

  Packet packet;
};

} // namespace limbo::udp
